////////////////////////////////////////////////////////////////////////////////////////////////////
/// \file	utils\WriterCatalog.h
///
/// \brief	In this file you can add more writers that fits your needs.
/// All writers have IListener as a parent class.
////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef	_ZELESTE_TOOLS_LOG_WRITER_CATALOG_H_
#define _ZELESTE_TOOLS_LOG_WRITER_CATALOG_H_

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include "GlobalLog.h"
#include <iostream>
#include <fstream>
#include "LogLevels.h"

namespace glog{

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// \class	CConsoleWriter
	///
	/// \brief	Console writer. Writes messages to console
	///
	/// \author	Ferran Ferri
	/// \date	04/12/2012
	////////////////////////////////////////////////////////////////////////////////////////////////////

	class CConsoleWriter: public IListener{
	private:
		LogLevel m_minimumLevel;
	public:

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	CConsoleWriter::CConsoleWriter(LogLevel lvl)
		///
		/// \brief	Constructor.
		///
		/// \author	Ferran Ferri
		/// \date	04/12/2012
		///
		/// \param	lvl	The minimun level that grants that message will be writen to console. 
		////////////////////////////////////////////////////////////////////////////////////////////////////

		CConsoleWriter(LogLevel lvl):m_minimumLevel(lvl){}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn void CConsoleWriter::writeToLog(const std::string& appender, LogLevel level, time_t time,
		/// const std::string& message)
		///
		/// \brief	Writes to log.
		///
		/// \author	Ferran Ferri
		/// \date	04/12/2012
		///
		/// \param	appender	The appender to which the message has been appended. 
		/// \param	level   	The level of the message. 
		/// \param	time		The time where the message has been added. 
		/// \param	message 	The message the message added. 
		////////////////////////////////////////////////////////////////////////////////////////////////////

		void writeToLog(const std::string& appender, LogLevel level, time_t time,const std::string& message){
			if (m_minimumLevel <= level)
			{
				std::cout << appender << "[" << levelToString(level) << "] "<< message << "\n";
			}
			 
		}

	};
	///=================================================================================================
	/// \class	CLogWriter
	///
	/// \brief	Log writer. 
	///
	/// \author	Ferran Ferri
	/// \date	12/07/2010
	/// 		
	///=================================================================================================

	class CLogWriter: public IListener{
	private:
		///Nombre del fichero para guardar el log
		std::string				m_fileName;
		///Nivel minimo de entrada.
		LogLevel	m_level;
		///Archivo donde se escribe el Log.
		std::fstream			m_file;
		///recursive path creator
		bool pathCreator(boost::filesystem::path path_to_create);
	public:

		///=================================================================================================
		/// \fn	CLogWriter(std::string fileName, LogLevel lvl)
		///
		/// \brief	Constructor. 
		///
		/// \author	Ferran Ferri
		/// \date	12/07/2010
		///
		/// \param	fileName	Name of the file. 
		/// \param	lvl			The lvl. 
		///=================================================================================================

		CLogWriter(const std::string fileName, LogLevel lvl);

		///=================================================================================================
		/// \fn	virtual ~CLogWriter(void)
		///
		/// \brief	Finaliser. 
		///
		/// \author	Ferran Ferri
		/// \date	12/07/2010
		///=================================================================================================

		~CLogWriter(void);

		///=================================================================================================
		/// \fn	void writeToLog(std::string appender, LogLevel level, time_t time, std::string message)
		///
		/// \brief	Writes to log. 
		///
		/// \author	Ferran Ferri
		/// \date	12/07/2010
		///
		/// \param	appender	The appender. 
		/// \param	level		The level. 
		/// \param	time		The time. 
		/// \param	message		The message. 
		///=================================================================================================

		void writeToLog(const std::string& appender, LogLevel level, time_t time,const std::string& message);
	};

	///=================================================================================================
	/// \class	CDev_null_writer
	///
	/// \brief	Dev null writer. Clase que ayuda a ignorar los mensajes sin salir de la filosofia del sistema de logs.
	///
	/// \author	Ferran Ferri
	/// \date	12/07/2010
	///=================================================================================================

	class CDev_null_writer: public IListener{

		///=================================================================================================
		/// \fn	void writeToLog(std::string appender, LogLevel level, time_t time, std::string message)
		///
		/// \brief	Escribe en dev null, o sea que ignora los mensajes.
		///
		/// \author	Ferran Ferri
		/// \date	12/07/2010
		///
		/// \param	appender	The appender. 
		/// \param	level		The level. 
		/// \param	time		The time. 
		/// \param	message		The message. 
		///=================================================================================================

		void writeToLog(const std::string& appender, LogLevel level, time_t time,const std::string& message){}

	};
}

#endif // _ZELESTE_TOOLS_LOG_WRITER_CATALOG_H_
